package com.qf.sy2103.fmmall.api.controller;

import com.qf.sy2103.common.vo.ResStatus;
import com.qf.sy2103.common.vo.ResultVO;
import com.qf.sy2103.fmmall.api.websocket.WebSocketServer;
import com.qf.sy2103.fmmall.beans.entity.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@CrossOrigin
//@RestController
//@RequestMapping("/music")
public class TestController {

//    @Autowired
//    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/detail")
    @Cacheable(cacheNames = "user")
    public ResultVO test1(String id,String name){
        System.out.println(id);
        System.out.println(name);
        final ResultVO resultVO = new ResultVO();
        resultVO.setCode(ResStatus.OK);
        resultVO.setMsg("successs");
        final Users users = new Users();
        users.setUsername("jack");
        users.setPassword("123456");
        resultVO.setData(users);
        return resultVO;
    }

    @RequestMapping("/testWebSocket")
    public ResultVO test2(String orderId){
        WebSocketServer.sendMsg(orderId,"1");
        return new ResultVO();
    }

    @RequestMapping("/mq")
    public ResultVO sendMq(String msg){
//        rabbitTemplate.convertAndSend("fmallExchage","fmall.order","order ok id is ...");
        return new ResultVO();
    }


    @RequestMapping("/fanout")
    public ResultVO fanout(String msg){
//        rabbitTemplate.convertAndSend("fanExchage","fmall.order",msg);
        return new ResultVO();
    }


}
